<?php
/**
 * WpCommandResolver.php
 * 
 * This file contains the WpCommandResolver class which is used to retrieve a command class instance specified by name
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage mvc.controller.resolver
 */

require_once(dirname(__FILE__).'/IWpResolver.php');

/**
 * This class is used to retrieve a command class instance used to handle a request
 * @author Robert Schmidt <robert@wildpack.de>
 * @version 1.0
 * @package wildpack
 * @subpackage mvc.controller.resolver
 */
class WpCommandResolver implements IWpResolver
{
	
	/**
	 * @var The path to lookup the classes
	 */
	public $Classpath = '';
		
	/**
	 * The class constructor
	 * @param array $config[optional] The configuration array
	 * @cfg classpath The path to the command classes
	 */
	public function __construct($config = null)
	{
		$this->Classpath = array_key_exists('classpath', $config) ? $config['classpath'] : $this->Classpath;
	}
	
	/**
   * Resolves a controller
   * @param string $subject The name of the subject to resolve
   * return object The controller object
   */
	function resolve($subject='')
	{
		if ($subject === '') {
			return null;
		}
		
		if (!file_exists($this->Classpath.$subject.'.php')) {
			return null;
		}
		
		include_once($this->Classpath.$subject.'.php');
		if (!class_exists($subject)) {
			return null;
		}
		$o = new $subject();
		return $o;
	}
}

/* End of file WpCommandResolver.php */
/* Location: ./wildpack/mvc/controller/resolver/WpCommandResolver.php */ 